package com.premedsidekick;
//ArrayAdapter to output custom ListView
//XML: homepage.xml
import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ProgressBar;
import android.widget.TextView;
public class SimpleArrayAdapterProgressBar extends ArrayAdapter<String> {
	private final Activity context;
	private final String[] names;
	//private int toggle;

	public SimpleArrayAdapterProgressBar(Activity context, String[] names) {
		super(context, R.layout.homepage, names);
		this.context = context;
		this.names = names;
		//this.toggle = toggle;
	}

	// static to save the reference to the outer class and to avoid access to
	// any members of the containing class
	static class ViewHolder {
		//public ImageView imageView; //toggle =1 for image
		public TextView textView; 
		public ProgressBar pBar;    //toggle =2 for progressBar
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// ViewHolder will buffer the assess to the individual fields of the row
		// layout

		ViewHolder holder;
		// Recycle existing view if passed as parameter
		// This will save memory and time on Android
		// This only works if the base layout for all classes are the same
		View rowView = convertView;
		if (rowView == null) {
			LayoutInflater inflater = context.getLayoutInflater();
			//inflate a new view hierarchy from XML source
			rowView = inflater.inflate(R.layout.homepage, null, true);
			holder = new ViewHolder();
			
			holder.textView = (TextView) rowView.findViewById(R.id.line1);
			holder.pBar = (ProgressBar) rowView.findViewById(R.id.rightbar);
			//Temporarily random number generator 
			holder.pBar.setProgress((int)Math.ceil(Math.random()*100));
			//
			rowView.setTag(holder);
		} else {
			holder = (ViewHolder) rowView.getTag();
		}

		holder.textView.setText(names[position]); //equivalent to xml android:text
		

		return rowView;
	}
}